import pygame
from . import constants as C

pygame.font.init()


class Info:
    def __init__(self, state, score):
        self.state = state
        self.state_labels = []
        self.score = score
        self.create_state_labels()
        self.create_info_labels()

    def create_state_labels(self):
        if self.state == "main_menu":
            self.state_labels.append((self.create_labels("1 开始游戏",
                                                         size=30), (292, 360)))
            self.state_labels.append((self.create_labels("2 退出",
                                                         size=30), (292, 405)))
        elif self.state == "load_screen":
            self.state_labels.append((self.create_labels("匹配中",
                                                         size=40), (315, 280)))
        elif self.state == "gaming":
            # self.state_labels.append((self.create_labels("游戏中",
            #                                              size=40), (315, 280)))
            pass
        elif self.state == "over":
            print("得分", self.score)
            self.state_labels.append(
                (self.create_labels("得分：", size=20,
                                    c=(255, 255, 255)), (520, 30)))
            self.state_labels.append(
                (self.create_labels("{}".format(self.score),
                                    size=20,
                                    c=(255, 255, 255)), (620, 30)))
            self.state_labels.append(
                (self.create_labels("游戏结束", size=40,
                                    c=(255, 255, 255)), (315, 280)))
        elif self.state == "error":
            self.state_labels.append(
                (self.create_labels("匹配错误，请重试", size=40,
                                    c=(255, 255, 255)), (315, 280)))

    def create_info_labels(self):
        self.info_labels = []
        self.info_labels.append((self.create_labels("制作人员 ",
                                                    size=20), (75, 30)))
        self.info_labels.append((self.create_labels("马志明 马鹏程 刘天翔",
                                                    size=20), (200, 30)))

    def create_labels(self,
                      label,
                      size=40,
                      width_scale=1.25,
                      height_scale=1,
                      c=(0, 0, 0)):
        # font = pygame.font.SysFont(C.SYS_FONT, size)
        font = pygame.font.Font('asset/方正粗黑宋简体.ttf', size)
        label_image = font.render(label, 1, c)  # 文字,抗锯齿,颜色
        rect = label_image.get_rect()
        label_image = pygame.transform.scale(
            label_image,
            (int(rect.width * width_scale), int(rect.height * height_scale)))
        return label_image

    def update(self, score):
        self.score = score

    def draw(self, surface):
        for label in self.state_labels:
            surface.blit(label[0], label[1])
        for label in self.info_labels:
            surface.blit(label[0], label[1])
